package FrontEnd.Helper;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

public class ExcelSaveChooser extends JFileChooser {
	private int auswahl;
	private String extension;
	private File newFile = null;
	public ExcelSaveChooser(File currentDirectory, File selectedFile, String extension){
		this.extension = extension;
		this.removeChoosableFileFilter(this.getChoosableFileFilters()[0]);
		this.setFileFilter(new MyFileFilter());
		this.setCurrentDirectory(currentDirectory);
		this.setSelectedFile(selectedFile);
		auswahl = this.showSaveDialog(null);
		if (auswahl != JFileChooser.APPROVE_OPTION)
			return;
		else {
			newFile = new File(this.getSelectedFile() + "." + extension);
		}
	}
	
	public int getAuswahl(){
		return auswahl;
	}

	public File getNewFile(){
		return newFile;
	}

	
class MyFileFilter extends FileFilter{
	@Override
	public boolean accept( File f )
	{
		return f.isDirectory() || f.getName().toLowerCase().endsWith( ".xlsx" )
		|| f.getName().toLowerCase().endsWith( ".xls" );

}

@Override
public String getDescription(){
	return "*."+extension;
	}
}
}
